<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>03_工厂模式</title>
</head>
<body>
<!-- 
方式三：工厂模式
    * 套路：通过工厂函数动态创建对象并返回
    * 适用场景：需要创建多个对象
    * 问题：对象没有一个具体的类型，都是Object类型
-->
<script>
function createPerson(name, age) {
    var obj = {
        name: name,
        age: age,
        setName: function(name) {
            this.name = name
        }
    }

    return obj;
}

var p1 = createPerson("Tom", 12)
console.log(p1.name, p1.age)
var p2 = createPerson("Jack", 18)
console.log(p2.name, p2.age)
</script>
</body>
</html>